﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace xna_game_engine.source
{
    abstract public class State_Base
    {
        // Members
        protected string mName;
        protected StateMachine.States mId;
        // Function "pointer" for event handling
        protected delegate void EventHandler();
        // Event lookup
        protected Dictionary<EventManager.Events, EventHandler> mEventHandlers;
        protected State_Base mParent;

        // Functions
        public State_Base(StateMachine.States id)
        {
            mId = id;
            mEventHandlers = new Dictionary<EventManager.Events, EventHandler>();
            mEventHandlers.Add(EventManager.Events.EVT_START_HIT, new EventHandler(DummyEventHandler));
            //mEventHandlers.Add(EventManager.Events.EVT_ENTER_HIT, new EventHandler(DummyEventHandler));
            mEventHandlers.Add(EventManager.Events.EVT_A_HIT, new EventHandler(DummyEventHandler));
            mEventHandlers.Add(EventManager.Events.EVT_B_HIT, new EventHandler(DummyEventHandler));
            mEventHandlers.Add(EventManager.Events.EVT_SELECT_HIT, new EventHandler(DummyEventHandler));
        }

        // Forced overrides
        abstract public void Init();
        abstract public void Enter();
        abstract public void Update(GameTime gameTime);
        abstract public void Draw();
        abstract public void Exit();

        // Functions
        public void HandleEvent(EventManager.Events eve)
        {
            if (mEventHandlers.ContainsKey(eve))
            {
                mEventHandlers[eve]();
            }
            //else if (mParent != null && mParent.mEventHandlers.ContainsKey(eve) && mParent.mEventHandlers[eve] != DummyEventHandler)
            //{
            //    mParent.mEventHandlers[eve]();
            //}
        }

        public void DummyEventHandler()
        {

        }

        // Properties
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }

        public StateMachine.States Id
        {
            get { return mId; }
        }
    }
}
